package hsb.ruoyi.common.utils.poi;

import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpServerResponse;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.io.OutputStream;

/**
 * @author 胡帅博
 * @date 2023/2/23 20:53
 */
public class HttpserverResponseOutputAdapter extends OutputStream {

    HttpServerResponse response;

    Buffer buffer = Buffer.buffer(1024);

    public HttpserverResponseOutputAdapter(HttpServerResponse response) {
        this.response = response;
    }

    @Override
    public void write(int b) throws IOException {
        //buffer.set

       // buffer.appendByte((byte) b);
       // System.out.println(buffer.length());
       response.write(Buffer.buffer(new byte[]{(byte)b}));
    }


    @Override
    public void write(@NotNull byte[] b, int off, int len) throws IOException {
       // buffer.appendBytes(b,off,len);
       // response.write(buffer);

        response.write(Buffer.buffer(len).appendBytes(b,off,len));

    }

    @Override
    public void flush() throws IOException {
        super.flush();
    }

    @Override
    public void close() throws IOException {
       // response.
        //response.write(buffer);
       // response.close();
        response.end();
    }
}
